import requests

import app

response = requests.post(url=app.BASE_URL + "/api/sys/login",
                         headers=app.HEADERS,
                         json={"mobile": "13800000002", "password": "123456"})
print("登陆的响应数据为: ", response.json())
token = response.json().get("data")
print("提取的令牌为: ", token)
app.HEADERS["Authorization"] = "Bearer " + token
print("保存到全局变量的令牌为: ", app.HEADERS)
response = requests.get(url=app.BASE_URL + "/api/sys/user?page=1&size=10",
                        headers=app.HEADERS)
print("查询员工列表信息为: ", response.json())
response = requests.post(url=app.BASE_URL + "/api/sys/user",
                         headers=app.HEADERS,
                         json={
                             "username": "尼古拉斯赵四",
                             "mobile": "13157778919",
                             "workNumber": "2020",
                             "timeOfEntry": "2020-01-01",
                             "formOfEmployment": "1",
                             "departmentId": "9527",
                             "departmentName": "北京27期测试部",
                             "correctionTime": "2020-12-04"
                         })
print("添加员工结果为: ",response.json())
app.EMP_ID = response.json().get("data").get("id")
response = requests.get(url=app.BASE_URL + "/api/sys/user" + "/" + app.EMP_ID,
                        headers=app.HEADERS)
print("查询员工的URL为: ",response.url)
print("添加后查询员工结果为: ", response.json())
response = requests.put(url=app.BASE_URL + "/api/sys/user" + "/" + app.EMP_ID,
                        headers=app.HEADERS,
                        json={"username": "小刚"})
print("修改后员工的URL为: ",response.url)
print("修改后的结果为: ", response.json())
# print(app.EMP_ID)
response = requests.get(url=app.BASE_URL + "/api/sys/user" + "/" + app.EMP_ID,
                        headers=app.HEADERS)
print("修改后查询员工结果为: ", response.json())
response = requests.delete(url=app.BASE_URL + "/api/sys/user" + "/" + app.EMP_ID,
                           headers=app.HEADERS)
print("删除后员工的URL为: ",response.url)
print("删除员工的结果为: ",response.json())
